<?php
include_once ("../Login/databaseconnection.php");
require_once ("../Login/config.php");
$q=$_GET["q"];
$hint="";
$name=explode(",",$q);
$nam=$name[0];
$tn=count($name);
for($i=1;$i<$tn;$i++)
{
if(empty($adr))
{
$adr=$name[$i];
}
else
{
$adr=$adr.",".$name[$i];
}
}
$results= mysql_query("SELECT * FROM school Where Name='$nam' AND Address='$adr'");
if($row = mysql_fetch_array($results))
{
$School_Id=$row['School_Id'];
}
$hint=$hint.'<select name="Competition_Name" id="Competition_Name" onChange="getComDate(this.value)">';
   if(isset($_POST['SaveChanges']))
	  {
	  $Competition_Id=$_SESSION['Comp_Id'];
   	  unset($_SESSION['Comp_Id']);
	  }
	     if($Competition_Id!="")
	  {
	  $resultnet=mysql_query("SELECT * FROM competitions WHERE Competition_Id='$Competition_Id'");
  if($rownet=mysql_fetch_array($resultnet))
  {
		$Competition_Name=$rownet['Competition_Name'];
}
	 $hint=$hint.'<option value="'.$Competition_Name.'">'.$Competition_Name.'</option>';
	  }
	  else
	  {
	  $hint=$hint.'<option value="Select One">Select One</option>';
	  }
			if($School_Id!="")
		{
			$com=mysql_query("SELECT DISTINCT(Competition_Id) FROM competition WHERE School_Id='$School_Id'");
		}
		if($School_Id=="")
		{
		  $com=mysql_query("SELECT DISTINCT(Competition_Id) FROM competition");
		}
  while($row=mysql_fetch_array($com))
  {
	 $Compe_Id=$row['Competition_Id'];
	 $resultnet=mysql_query("SELECT * FROM competitions WHERE Competition_Id='$Compe_Id'");
  if($rownet=mysql_fetch_array($resultnet))
  {
		$Compe_Name=$rownet['Competition_Name'];
}
if($Competition_Name!=$Compe_Name)
{
	  $hint=$hint.'<option value="'.$Compe_Name.'">'.$Compe_Name.'</option>';
	  }
  }
      $hint=$hint.'</select>';
	  if($hint=="")
{
$response=$response.'<select name="Competition_Name" id="Competition_Name" onChange="getComDate(this.value)">';
$response=$response.'<option value="Select One">Select One</option>';
	 $c=mysql_query("SELECT DISTINCT(Competition_Id) FROM competition");	  
  while($row=mysql_fetch_array($c))
  {
  $Compe_Id=$row['Competition_Id'];
   $resultnet=mysql_query("SELECT * FROM competitions WHERE Competition_Id='$Compe_Id'");
  if($rownet=mysql_fetch_array($resultnet))
  {
   $c_Name=$rownet['Competition_Name'];
   }
	$response=$response.'<option value="'.$c_Name.'">'.$c_Name.'</option>';
  }
$response=$response.'</select>';
}
else
{
$response=$hint;
}
echo $response;
?>